package main

import (
	"docker_go/common/global"
	"docker_go/internal/models/entity"
	"docker_go/internal/routers"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"net/http"
	"time"
)

func init() {
	db, _ := gorm.Open("mysql", "root:root@(127.0.0.1:3305)/db1?charset=utf8mb4&parseTime=True&loc=Local")
	global.DBEngine = db
	db.SingularTable(true)
	db.AutoMigrate(entity.Student{})
}

func main() {
	//r := gin.Default()
	//r.GET("ping", func(c *gin.Context) {
	//	c.JSON(200, gin.H{
	//		"message": "pong",
	//	})
	//})
	//err := r.Run()
	//if err != nil {
	//	return
	//}
	router := routers.NewRouter()
	s := &http.Server{
		Addr:           ":8000",
		Handler:        router,
		ReadTimeout:    60 * time.Second,
		WriteTimeout:   60 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	_ = s.ListenAndServe()
}
